#pragma once
#pragma execution_character_set("utf-8")
#include <qwidget.h>
#include <qpainter.h>
#include <qvector.h>
#include <qpoint.h>
#include <qrect.h>
#include <QPaintEvent>
#include <acoutectoolscore_global.h>

struct RadarPosition
{
	QString Text;
};
struct RadarLine
{
	RadarLine()
	{
		Show = true;
	}
	QString Name;
	QVector<double> Values;
	QColor LineColor;
	bool ShowValueText;
	QColor FillColor;
	double LineWidth;
	bool Show;
};

class ACOUTECTOOLSCORE_EXPORT RadarChart :public QWidget
{
	Q_OBJECT
private:
	const double PI = 3.1415926;
	QRectF m_rectWorking;
	QPointF m_center;
	int m_split_count = 5;
	QVector<RadarLine> m_lines;
	QVector<RadarPosition> m_positions;

	QColor m_background = Qt::transparent;

	QString m_title;
	QFont m_title_font;
	QColor m_title_color = Qt::gray;

	QFont m_position_font;
	QFont m_value_font;

	bool m_use_round_split = true;
	QColor m_split_odd_color = QColor::fromRgb(197, 199, 206,100);
	QColor m_split_even_color = Qt::white;
	QColor m_grid_color = Qt::gray;


	QColor m_position_color = Qt::gray;
	QColor m_value_color = Qt::black;

	double m_max_val = 100;

	
private:
	QSize MesureStringSize(QPainter* p, const QFont& font, const QString& text);
	QPointF GetPointByAngle(QPointF centrePoint, double fltAngle, double fltRadiusWidth);
	void draw_text(QPainter* p, const QPointF& point, double angle, const QString& text);

	void paint(QPainter& p, const QSize& rec_size);
public:
	RadarChart(QWidget *parent = Q_NULLPTR) :QWidget(parent) {};
	virtual void paintEvent(QPaintEvent* ev);

public:
	void add_line(RadarLine& line);
	void remove_line(RadarLine& line);
	void remove_line(const QString& name);
	void set_position(QVector<RadarPosition>& position);
	void clear();

	void set_background(const QColor& color);
	void set_split_count(int count);
	void set_use_round(bool round);
	void set_max_val(double max);
	void set_odd_color(const QColor& color);
	void set_even_color(const QColor& color);
	void set_grid_color(const QColor& color);

	void set_title(const QString& title);
	void set_title_font(const QFont& font);
	void set_title_color(const QColor& color);

	void set_position_color(const QColor& color);
	void set_value_color(const QColor& color);

	void set_position_font(const QFont& font);
	void set_value_font(const QFont& font);

	QPixmap toPixmap(const QSize& size);
};
